#include"Stack.h"

void Stinit(St* s) {
	s->capacity = 4;
	s->arr = (StDateType*)malloc(s->capacity * sizeof(StDateType));
	assert(s->arr != NULL);
	s->top = 0;
}

void StackDestory(St* s)
{
	free(s->arr);
	s->arr = NULL;
	s->top = 0;
	s->capacity = 0;
}

void Stackpushtop(St* s, StDateType data)
{
	if (s->top == s->capacity) 
	{
		s->capacity *= 2; 
		s->arr = (StDateType*)realloc(s->arr, s->capacity * sizeof(StDateType));
		assert(s->arr != NULL); 
	}
	s->arr[s->top++] = data;
}

bool Stackempty(St*s)
{
	return s->top==0;
}

void Stackpop(St* s)
{
	assert(!Stackempty(s));
	s->top--;
}

StDateType Stacktop(St* s)
{
	assert(!Stackempty(s));
	return s->arr[s->top - 1];
}

int Stacksize(St* s)
{
	return s->top;
}